<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
*返回json错误
*/
function returnResult($errcode=-1,$errmsg='fail'){
    $data=array();
    $data['errcode']=$errcode;
    $data['errmsg']=$errmsg;
    echo json_encode($data);
    exit;
}
/**
 * 字段为空的字段
 */
function chk($value,$errmsg){
    if(empty($value)){
        returnResult(400001,$errmsg);
    }else{
        return $value;
    }

}
/**
 * 通过session去防止多次提交
 */
function validDo(){
    $lastTime=(int)session('lastTime');
    if($lastTime>time()-5){
        returnResult(300231,'请求已发送,请耐心等待哦~');
    }else{
        session('lastTime',time());
    }
}
